package test.executor;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * Created by crj on 2017/8/10.
 */
class ThreadPoolExecutorService  implements  IThreadPoolExecutorService{
    private int corePoolSize;
    private int maxPoolsize;
    private long keepAliveTime;
    private int  queueCapacity;
    RejectedExecutionHandler rejectedExecutionHandler;

    @Override
    public ThreadPoolExecutor createNewThreadPool(){
        ThreadPoolExecutor executor = new ThreadPoolExecutor(getCorePoolSize(),getMaxPoolsize(),getKeepAliveTime(), TimeUnit.SECONDS,new ArrayBlockingQueue(getQueueCapacity()),getRejectedExecutionHandler());
        return executor;
    }
    @Override
    public int getCorePoolSize() {
        return corePoolSize;
    }
    @Override
    public void setCorePoolSize(int corePoolSize) {
        this.corePoolSize = corePoolSize;
    }
    @Override
    public int getMaxPoolsize() {
        return maxPoolsize;
    }
    @Override
    public void setMaxPoolsize(int maxPoolsize) {
        this.maxPoolsize = maxPoolsize;
    }
    @Override
    public long getKeepAliveTime() {
        return keepAliveTime;
    }
    @Override
    public void setKeepAliveTime(long keepAliveTime) {
        this.keepAliveTime = keepAliveTime;
    }
    @Override
    public int getQueueCapacity() {
        return queueCapacity;
    }
    @Override
    public void setQueueCapacity(int queueCapacity) {
        this.queueCapacity = queueCapacity;
    }
    @Override
    public RejectedExecutionHandler getRejectedExecutionHandler() {
        return rejectedExecutionHandler;
    }
    @Override
    public void setRejectedExecutionHandler(RejectedExecutionHandler rejectedExecutionHandler) {
        this.rejectedExecutionHandler = rejectedExecutionHandler;
    }
}

